package tw.com.hitevision.whiteboard.android.render;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.DashPathEffect;
import android.graphics.Paint;
import android.graphics.Path;

import androidx.core.content.ContextCompat;
import tw.com.hitevision.whiteboard.android.R;

//import static tw.com.hitevision.whiteboard.android.widgets.HexagonPalette.DEFAULT_ALPHA;

public class ObjectEraserPen extends Line {
    private Paint eraserPaint;
    private Path eraserRenderPath;

    public ObjectEraserPen(Context context, float x, float y, float thickness) {
        super(context, x, y, thickness);
        init(context);
    }

    private void init(Context context) {

        int fillColor = ContextCompat.getColor(context, R.color.eraserTrack);
        setColor(fillColor);
        eraserPaint = new Paint();
        eraserPaint.setStyle(Paint.Style.STROKE);
        eraserPaint.setStrokeWidth(6f);
        eraserPaint.setColor(fillColor);
        eraserPaint.setPathEffect(new DashPathEffect(new float[]{27f ,18f },-0f ));
        eraserPaint.setAntiAlias(true);
        thickness = context.getResources().getDimensionPixelSize(R.dimen.eraser_vertical_offset);
    }

    @Override
    public void clear() {
        super.clear();
    }

    @Override
    public void add(float x, float y) {
        super.add(x, y);
        if(eraserRenderPath == null){
            eraserRenderPath = new Path();
            eraserRenderPath.moveTo(x, y);
        }else{
            eraserRenderPath.lineTo(x,y);
        }
    }

    @Override
    public void render(Canvas canvas, Paint paint, Context context) {
        if (points.isEmpty()) {
            return;
        }

        if(needUpdatePath) {
            updatePath();
        }

        canvas.drawPath(eraserRenderPath, eraserPaint);
    }
}
